<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文档管理 - 控制面板</title>
    <link rel="stylesheet" href="/css/style.css">
    <style>
        .document-list {
            margin-top: 20px;
        }
        .document-item {
            border-bottom: 1px solid #eee;
            padding: 15px 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .document-info {
            flex: 1;
        }
        .document-title {
            font-size: 18px;
            font-weight: bold;
            color: #333;
            margin-bottom: 5px;
        }
        .document-meta {
            color: #666;
            font-size: 14px;
        }
        .document-actions {
            display: flex;
            gap: 10px;
        }
        .btn-small {
            padding: 5px 10px;
            font-size: 14px;
        }
        .featured-badge {
            display: inline-block;
            padding: 3px 8px;
            background-color: #4CAF50;
            color: white;
            border-radius: 4px;
            font-size: 12px;
            margin-left: 10px;
        }
        .empty-state {
            text-align: center;
            padding: 50px 20px;
            color: #666;
        }
    </style>
</head>
<body>
    <div class="dashboard-container">
        <div class="sidebar">
            <div class="sidebar-header">
                <h2>控制面板</h2>
            </div>
            <ul class="sidebar-menu">
                <li><a href="/dashboard">主页</a></li>
                <li><a href="/dashboard/profile">个人信息</a></li>
                <li><a href="/dashboard/change-password">修改密码</a></li>
                <li class="active"><a href="/dashboard/documents">文档管理</a></li>
                <li><a href="/" target="_blank">访问首页</a></li>
                <li><a href="/logout">退出登录</a></li>
            </ul>
        </div>
        
        <div class="main-content">
            <div class="dashboard-header">
                <div class="dashboard-title">
                    <h1>文档管理</h1>
                </div>
                <div>
                    <a href="/dashboard/documents/create" class="btn btn-primary">创建新文档</a>
                </div>
            </div>
            
            <div th:if="${successMessage}" class="alert alert-success" th:text="${successMessage}"></div>
            <div th:if="${errorMessage}" class="alert alert-danger" th:text="${errorMessage}"></div>
            
            <div th:if="${documents.empty}" class="empty-state">
                <p>您还没有创建任何文档。点击"创建新文档"按钮开始创建。</p>
            </div>
            
            <div th:unless="${documents.empty}" class="document-list">
                <div th:each="document : ${documents}" class="document-item">
                    <div class="document-info">
                        <div class="document-title">
                            <span th:text="${document.title}">文档标题</span>
                            <span th:if="${document.featured}" class="featured-badge">首页显示</span>
                        </div>
                        <div class="document-meta">
                            <span th:text="${'作者: ' + document.author}">作者: 未知</span> | 
                            <span th:text="${'创建时间: ' + #temporals.format(document.createdAt, 'yyyy-MM-dd HH:mm')}">创建时间: 2023-01-01</span> | 
                            <span th:text="${'更新时间: ' + #temporals.format(document.updatedAt, 'yyyy-MM-dd HH:mm')}">更新时间: 2023-01-01</span>
                        </div>
                    </div>
                    <div class="document-actions">
                        <a th:href="@{'/documents/' + ${document.id}}" class="btn btn-small btn-info">查看</a>
                        <a th:href="@{'/dashboard/documents/edit/' + ${document.id}}" class="btn btn-small btn-primary">编辑</a>
                        <a th:href="@{'/dashboard/documents/toggle-featured/' + ${document.id}}" class="btn btn-small" 
                           th:classappend="${document.featured ? 'btn-warning' : 'btn-success'}"
                           th:text="${document.featured ? '取消首页显示' : '设为首页显示'}">
                            首页显示
                        </a>
                        <a th:href="@{'/dashboard/documents/delete/' + ${document.id}}" class="btn btn-small btn-danger" 
                           onclick="return confirm('确定要删除这个文档吗？此操作不可撤销。')">删除</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="/js/script.js"></script>
</body>
</html> 